CMAKE_MINIMUM_REQUIRED(VERSION 3.10)

PROJECT(Alliance_Sentry_V2_1)
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_BUILD_TYPE RELEASE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
add_definitions(-fgnu89-inline)
#相当于define PATH
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPATH=\"\\\"${PROJECT_SOURCE_DIR}\\\"\"")
MESSAGE(STATUS "PATH:" ${PROJECT_SOURCE_DIR})
#相当于会define linux
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${CMAKE_SYSTEM_NAME}")
SET(BIN_NAME "Alliance_Sentry_V2_1")

FIND_FILE(CONFIG_FOUND "config.h" "others/include/config")
if (CONFIG_FOUND)
    MESSAGE("Found config.h")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWITH_CONFIG")
endif()


FIND_PROGRAM(CCACHE_FOUND ccache)
IF(CCACHE_FOUND)
    SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
    SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
    MESSAGE("< Use ccache for compiler >")
ENDIF()

#FIND_PACKAGE(Eigen3 REQUIRED)
FIND_PACKAGE(OpenCV 4 REQUIRED)
FIND_PACKAGE(Threads)
find_package(PythonLibs 2.7)
#FIND_PACKAGE( OpenMP REQUIRED)
#if(OPENMP_FOUND)
#    message("OPENMP FOUND")
#    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
#    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
#    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
#endif()

LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/others)

INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/cvui)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/armor/include)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/others/include)

FILE(GLOB_RECURSE sourcefiles "others/src/*.cpp" "armor/src/*.cpp")
ADD_EXECUTABLE(${BIN_NAME} main.cpp ${sourcefiles} armor/include/SENTRYTHREAD.h armor/src/SENTRYTHREAD.cpp others/include/Setter.h others/src/Setter.cpp others/include/log.h armor/include/armor_finder.h armor/src/armor_finder.cpp armor/include/find/CNN.h armor/src/find/CNN.cpp armor/include/solve/solve_PNP.h armor/src/solve/solve_PNP.cpp armor/src/solve/pos_resolve.cpp armor/include/solve/trajectory_resolve.h armor/src/solve/trajectory_resolve.cpp armor/include/solve/Predictor.h armor/src/solve/Predictor.cpp armor/include/solve/SmoothKF.h armor/src/solve/SmoothKF.cpp)

target_include_directories(${BIN_NAME} PRIVATE ${PYTHON_INCLUDE_DIRS})

target_link_libraries(${BIN_NAME} ${PYTHON_LIBRARIES})
TARGET_LINK_LIBRARIES(${BIN_NAME} ${CMAKE_THREAD_LIBS_INIT})
TARGET_LINK_LIBRARIES(${BIN_NAME} ${OpenCV_LIBS})

IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    MESSAGE(STATUS "current platform: Linux ")
    TARGET_LINK_LIBRARIES(${BIN_NAME} "${PROJECT_SOURCE_DIR}/others/libMVSDK1.so")
    #[[ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
        MESSAGE(STATUS "current platform: Windows")
        TARGET_LINK_LIBRARIES(${BIN_NAME} "${PROJECT_SOURCE_DIR}/others/MVCAMSDK_X64.lib")
    ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
        MESSAGE(STATUS "current platform: Mac")
        TARGET_LINK_LIBRARIES(${BIN_NAME} "${PROJECT_SOURCE_DIR}/others/libmvsdk.dylib")
    ELSE ()
        MESSAGE(STATUS "Unsupport platform: ${CMAKE_SYSTEM_NAME}")]]
ENDIF()